package com.green.aop.advice;

import org.aspectj.lang.annotation.After;
import org.aspectj.lang.annotation.Aspect;
import org.aspectj.lang.annotation.Before;
import org.aspectj.lang.annotation.Pointcut;
import org.springframework.stereotype.Component;

import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter;

/**
 * 切面类
 */
@Aspect
@Component
public class LoggingAdvice {

    @Pointcut("execution(* com.green.aop.service.IUserService.addUser(..))")
    public void test1(){};

    //扩展功能的方法称为：增强、通知
    //1、确定要加在哪些方法上，2、要确定什么时候执行，例如执行方法前，执行方法后、前后都需要等
    @After("test1()")
    public void printLog() {
        String format = LocalDateTime.now().format(DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss"));
        System.out.println("后操作时间=====>" + format);
    }


    @Before("test1()")
    public void beforePrintLog() {
        String format = LocalDateTime.now().format(DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss"));
        System.out.println("前操作时间=====>" + format);
    }
}
